using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HostMonitor
{
    public partial class NewHostFrm : Form
    {
        private HostsData _hosts;

        protected NewHostFrm(HostsData hosts)
        {
            InitializeComponent();
            _hosts = hosts;
            cbGroup.DataSource = _hosts.Groups;
            cbGroup.DisplayMember = "GroupName";
        }

        static public void OpenDialog(HostsData hosts)
        {
            NewHostFrm frm = new NewHostFrm(hosts);
            frm.ShowDialog();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            HostsData.HostsRow row = _hosts.Hosts.NewHostsRow();
            row.HostName = tbName.Text;
            row.Description = tbDesc.Text;
            row.Group = cbGroup.Text;
            row.Active = cbActive.Checked;                        
            _hosts.Hosts.AddHostsRow(row);
            row.AcceptChanges();
            //HostsData.HostsRow row = _hosts.Hosts.AddHostsRow(tbName.Text, cbGroup.Text, tbDesc.Text, cbActive.Checked);

            Close();
        }
    }
}